import java.util.Arrays;

public class Test04 {

    public static void main7(String[] args) {
        int[]arr=new int[]{1,18,97,0,6,18,91,165,651};

        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        int ret=Arrays.binarySearch(arr,1,3,6);
        System.out.println(ret);
//        Arrays.sort(arr);
//        System.out.println(Arrays.toString(arr));
    }
    public static int findret(int arry[],int key){
        for(int i=0;i< arry.length;i++){
            for(int j=0;j<arry.length-i;i++);
        }
        int left=0;
        int right=arry.length-1;;
        while(left<=right){
            int ret=(left+right)/2;
            if(arry[ret]==key){
                return ret;
            }else if(arry[ret]<key){
                left=ret+1;
            }else{
                right=ret-1;
            }
        }
        return -1;
    }
    public static void main6(String[] args) {
        //使用二分法查找数据,返回期所对应的下标
        int[]arr=new int[]{1,2,3,4,5,6,7,8,9,10,11,12,13};
        int key=20;
        int ret=findret(arr,key);
        System.out.println(ret);
    }
    public static String myToString(int[]arr){
        String ret="[";
        for (int i = 0; i < arr.length; i++) {
            ret+=arr[i];
            if(i!= arr.length-1){
                ret+=',';
            }
        }
        ret+=']';
        return ret;
    }
    public static void main5(String[] args) {
        int[]arr=new int[]{1,2,3,4,5,6};
        System.out.println(myToString(arr));

    }
    public static int[] kuoda2(int[]arr){
        int[] ret=new int[arr.length];
        for(int i=0;i<arr.length;i++){
            ret[i]=arr[i]*2;
        }
        return ret;
    }
    public static int[] kuoda(int[]arr){
        for(int i=0;i<arr.length;i++){
            arr[i]=arr[i]*2;
        }
        return arr;
    }
    public static void main4(String[] args) {
        //把数组中所有数据扩大2倍
        int[]arr1=new int[]{1,2,3,4,5,6};
        int[]arr2=kuoda2(arr1);

        System.out.println(Arrays.toString(arr1));
        System.out.println(Arrays.toString(arr2));
        System.out.println(Arrays.toString(arr1));
    }
    public static void main3(String[] args) {
        int[]arr=null;//不指向任何东西
        System.out.println(arr.length);
    }
    public static void main2(String[] args) {
        int []arry1=new int[3];
        arry1[0]=10;
        arry1[1]=20;
        arry1[2]=30;
        int []arry2=new int[]{1,2,3,4,5};
        arry2[0]=100;
        arry2[1]=200;
        arry1=arry2;
        arry1[2]=300;
        arry1[3]=400;
        arry1[4]=500;
        for(int i=0;i<arry1.length;i++){
            System.out.println(arry2[i]);
        }
    }
    public static int max2(int x,int y){
        return x>y?x:y;
    }
    public static int max3(int x,int y,int z){
        if(x>y){
            return max2(x,z);
        }
        else{
            return max2(y,z);
        }
    }
    public static void main1(String[] args){
        //创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
        //要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算
        int a=10,b=20,c=30;
        int max=max2(a,b);
        int Max=max3(a,b,c);
        System.out.println(max);
        System.out.println(Max);
    }
}
